/**
 * 商品列表服务
 */
angular.module('goodsList.service', [])
  .factory('GoodsListFty', function ($q) {
    return {
      // 1.刷新商品列表
      getCategoryData: function (text) {
        $i = 0;
        var categoryData = []
        var list = [
          {
            name: "所有商品",
            Number: '1001',
            category:'蜜雪冰城'
          },
          {
            name: "奶茶",
            Number: '1002',
            category:'蜜雪冰城'
          },
          {
            name: "其他",
            Number: '1003',
            category:'蜜雪冰城'
          },{
            name: "全部",
            Number: '1011',
            category:'花雕醉鸡'
          },{
            name: "必点",
            Number: '1012',
            category:'花雕醉鸡'
          },{
            name: "加菜",
            Number: '1013',
            category:'花雕醉鸡'
          }
        ];
        if(text == 10000){
          while($i<list.length){
            if(list[$i].category == '蜜雪冰城'){
              categoryData.push(list[$i])
              $i++
            }else{
              $i++
            }
          }
        }else if(text == 10001){
          while($i<list.length){
            if(list[$i].category == '花雕醉鸡'){
              categoryData.push(list[$i])
              $i++
            }else{
              $i++
            }
          }
        }
        // 假设数据请求成功
        var deferred = $q.defer();
        deferred.resolve(categoryData);
        // console.log(deferred.promise)
        return deferred.promise;
      },
      refreshGoodsList: function (Number) {
        $i = 0;
        var goodsListData_1 = [
          {
            name: '莓莓奶麻薯',
            price: '15.8',
            haoping: '9999+',
            buy: '9999+',
            productId: "0",
            src: 'img/home/seckill_1.jpg',
            category1:'饮品',
            category2:'所有商品',
          }, {
            name: '芝士奶盖四季春',
            price: '10',
            haoping: '9000',
            buy: '9999+',
            productId: "1",
            src: 'img/goodsList/goods1.jpg',
            category1:'饮品',
            category2:'所有商品',            
          }, {
            name: '港式杨梅甘露',
            price: '15.88',
            haoping: '700',
            buy: '733',
            productId: "2",
            src: 'img/goodsList/goods2.jpg',
            category1:'饮品',
            category2:'所有商品',
          }, {
            name: '芋圆葡萄',
            price: '20',
            haoping: '100',
            buy: '333',
            productId: "3",
            src: 'img/goodsList/goods3.jpg',
            category1:'饮品',
            category2:'所有商品',
          }, {
            name: '厚芋泥奶茶',
            price: '30',
            haoping: '100',
            buy: '133',
            productId: "4",
            src: 'img/goodsList/goods4.jpg',
            category1:'饮品',
            category2:'所有商品',
          },
          {
            name: '珍珠奶茶',
            price: '25',
            haoping: '700',
            buy: '773',
            productId: "5",
            src: 'img/goodsList/goods5.jpg',
            category1:'饮品',
            category2:'所有商品',
          },
          {
            name: '椰果奶茶',
            price: '25.9',
            haoping: '77',
            buy: '89',
            productId: "6",
            src: 'img/goodsList/goods6.jpg',
            category1:'饮品',
            category2:'所有商品',
          },
          {
            name: '奥利奥雪王大圣代',
            price: '22.9',
            haoping: '99',
            buy: '215',
            productId: "7",
            src: 'img/goodsList/goods7.jpg',
            category1:'饮品',
            category2:'所有商品',
          },
          {
            name: '三拼霸霸奶茶',
            price: '25.9',
            haoping: '9',
            buy: '19',
            productId: "8",
            src: 'img/goodsList/goods8.jpg',
            category1:'饮品',
            category2:'所有商品',
          },
          {
            name: '珍珠奶茶',
            price: '15.8',
            haoping: '69',
            buy: '88',
            productId: "9",
            src: 'img/goodsList/goods9.jpg',
            category1:'饮品',
            category2:'所有商品',
          }, {
            name: '蜜桃四季春',
            price: '19.9',
            haoping: '700',
            buy: '888',
            productId: "10",
            src: 'img/goodsList/goods10.jpg',
            category1:'饮品',
            category2:'所有商品',
          }, {
            name: '桃喜芒芒',
            price: '9',
            haoping: '888',
            buy: '900',
            productId: "11",
            src: 'img/goodsList/goods11.jpg',
            category1:'饮品',
            category2:'所有商品',
          }, {
            name: '菠萝甜心橙',
            price: '12.9',
            haoping: '999',
            buy: '900',
            productId: "12",
            src: 'img/goodsList/goods12.jpg',
            category1:'饮品',
            category2:'所有商品',
          }, {
            name: '菠萝爱情海',
            price: '29.9',
            haoping: '666',
            buy: '600',
            productId: "13",
            src: 'img/goodsList/goods13.jpg',
            category1:'饮品',
            category2:'所有商品',
          }, {
            name: '百香芒芒',
            price: '29.9',
            haoping: '9999+',
            buy: '9000',
            productId: "14",
            src: 'img/goodsList/goods14.jpg',
            category1:'饮品',
            category2:'所有商品',
          }, {
            name: '咖啡椰椰',
            price: '15.9',
            haoping: '555',
            buy: '500',
            productId: "15",
            src: 'img/goodsList/goods15.jpg',
            category1:'饮品',
            category2:'所有商品',
          }, {
            name: '小油条(店主推荐)',
            price: '15.9',
            haoping: '555',
            buy: '500',
            productId: "27",
            src: 'img/goodsList/花雕醉鸡1.jpg',
            category1:'全部',
            category2:'加菜',
          }, {
            name: '涮汁娃娃菜',
            price: '15.9',
            haoping: '555',
            buy: '500',
            productId: "28",
            src: 'img/goodsList/花雕醉鸡2.jpg',
            category1:'全部',
            category2:'加菜',
          }, {
            name: '五年陈醉鸡双人份',
            price: '15.9',
            haoping: '555',
            buy: '500',
            productId: "29",
            src: 'img/goodsList/花雕醉鸡3.jpg',
            category1:'全部',
            category2:'必点',
          }, {
            name: '独享醉鸡+米饭',
            price: '15.9',
            haoping: '555',
            buy: '500',
            productId: "30",
            src: 'img/goodsList/花雕醉鸡4.jpg',
            category1:'全部',
            category2:'必点',
          }, {
            name: '独享醉鸡+土豆粉',
            price: '15.9',
            haoping: '555',
            buy: '500',
            productId: "31",
            src: 'img/goodsList/花雕醉鸡5.jpg',
            category1:'全部',
            category2:'必点',
          }, {
            name: '贡菜',
            price: '15.9',
            haoping: '555',
            buy: '500',
            productId: "32",
            src: 'img/goodsList/花雕醉鸡6.jpg',
            category1:'全部',
            category2:'加菜',
          }
        ];
        var obj_goodsListData = [];
        // console.log(Number);
        if (Number == 1001) {
          while($i<goodsListData_1.length){
            obj_goodsListData.push(goodsListData_1[$i]);
            $i++;
          }
          // 假设数据请求成功
        } 
        else if(Number == 1002){
          while($i<goodsListData_1.length){
            if(goodsListData_1[$i].category1 == '饮品'){
              obj_goodsListData.push(goodsListData_1[$i]);
              $i++;
            }else $i++;
          }
        }else if(Number == 1003){
          while($i<goodsListData_1.length){
            if(goodsListData_1[$i].category1 == '其他'){
              obj_goodsListData.push(goodsListData_1[$i]);
              $i++;
            }else $i++;
          }
        }else if(Number == 1011){
          while($i<goodsListData_1.length){
            if(goodsListData_1[$i].category1 == '全部'){
              obj_goodsListData.push(goodsListData_1[$i]);
              $i++;
            }else $i++;
          }
        }else if(Number == 1012){
          while($i<goodsListData_1.length){
            if(goodsListData_1[$i].category2 == '必点'){
              obj_goodsListData.push(goodsListData_1[$i]);
              $i++;
            }else $i++;
          }
        }else if(Number == 1013){
          while($i<goodsListData_1.length){
            if(goodsListData_1[$i].category2 == '加菜'){
              obj_goodsListData.push(goodsListData_1[$i]);
              $i++;
            }else $i++;
          }
        }
        // else
        // {
        //   obj_goodsListData = [];
        //   // 假设数据请求成功
        //   var deferred = $q.defer();
        //   deferred.resolve(obj_goodsListData);
        //   return deferred.promise;
        // }
        var deferred = $q.defer();
        deferred.resolve(obj_goodsListData);
        return deferred.promise;
      },
      //2.下拉加载更多列表商品
      loadMoreGoodsList: function (message) {
        //第一页展示6条数据
        // JSON.parse(message)
        console.log(JSON.parse(message).typeNumber)
        if(JSON.parse(message).typeNumber == 10000){
          var obj_goodsListData = [
            {
              name: '冰鲜柠檬水',
              price: '15.8',
              haoping: '9999+',
              buy: '9999+',
              productId: "16",
              src: 'img/goodsList/goods16.jpg'
            },{
              name: '港式杨枝甘露(芋圆版)',
              price: '15.8',
              haoping: '9999+',
              buy: '9999+',
              productId: "17",
              src: 'img/goodsList/goods17.jpg'
            },{
              name: '草莓啵啵',
              price: '15.8',
              haoping: '9999+',
              buy: '9999+',
              productId: "18",
              src: 'img/goodsList/goods18.jpg'
            },{
              name: '黄桃果霸',
              price: '15.8',
              haoping: '9999+',
              buy: '9999+',
              productId: "19",
              src: 'img/goodsList/goods19.jpg'
            },{
              name: '芋圆葡萄',
              price: '15.8',
              haoping: '9999+',
              buy: '9999+',
              productId: "20",
              src: 'img/goodsList/goods20.jpg'
            },{
              name: '满杯百香果',
              price: '15.8',
              haoping: '9999+',
              buy: '9999+',
              productId: "21",
              src: 'img/goodsList/goods21.jpg'
            },{
              name: '鲜橙益菌多',
              price: '15.8',
              haoping: '9999+',
              buy: '9999+',
              productId: "22",
              src: 'img/goodsList/goods22.jpg'
            },{
              name: '柠檬绿茶',
              price: '15.8',
              haoping: '9999+',
              buy: '9999+',
              productId: "23",
              src: 'img/goodsList/goods23.jpg'
            },{
              name: '柠檬红茶',
              price: '15.8',
              haoping: '9999+',
              buy: '9999+',
              productId: "24",
              src: 'img/goodsList/goods24.jpg'
            },{
              name: '棒打鲜橙',
              price: '15.8',
              haoping: '9999+',
              buy: '9999+',
              productId: "25",
              src: 'img/goodsList/goods25.jpg'
            },{
              name: '蜜桃四季春',
              price: '15.8',
              haoping: '9999+',
              buy: '9999+',
              productId: "26",
              src: 'img/goodsList/goods26.jpg'
            }
          ];
        }else if(JSON.parse(message).typeNumber == 10001){
          var obj_goodsListData = [
            {
              name: '小油条(店主推荐)',
              price: '15.9',
              haoping: '555',
              buy: '500',
              productId: "33",
              src: 'img/goodsList/花雕醉鸡1.jpg',
              category1:'全部',
              category2:'加菜',
            }, {
              name: '涮汁娃娃菜',
              price: '15.9',
              haoping: '555',
              buy: '500',
              productId: "34",
              src: 'img/goodsList/花雕醉鸡2.jpg',
              category1:'全部',
              category2:'加菜',
            }, {
              name: '五年陈醉鸡双人份',
              price: '15.9',
              haoping: '555',
              buy: '500',
              productId: "35",
              src: 'img/goodsList/花雕醉鸡3.jpg',
              category1:'全部',
              category2:'必点',
            }, {
              name: '独享醉鸡+米饭',
              price: '15.9',
              haoping: '555',
              buy: '500',
              productId: "36",
              src: 'img/goodsList/花雕醉鸡4.jpg',
              category1:'全部',
              category2:'必点',
            }, {
              name: '独享醉鸡+土豆粉',
              price: '15.9',
              haoping: '555',
              buy: '500',
              productId: "37",
              src: 'img/goodsList/花雕醉鸡5.jpg',
              category1:'全部',
              category2:'必点',
            }, {
              name: '贡菜',
              price: '15.9',
              haoping: '555',
              buy: '500',
              productId: "38",
              src: 'img/goodsList/花雕醉鸡6.jpg',
              category1:'全部',
              category2:'加菜',
            }
          ]
        }
        else{
          var obj_goodsListData =[]
        }
        var deferred = $q.defer();
          deferred.resolve(obj_goodsListData);
          return deferred.promise;
        // 假设加载更多数据成功
        
      },
      List: function (message) {
        var obj_goodsListData = [
          {
            name: '莓莓奶麻薯',
            price: '15.8',
            haoping: '9999+',
            buy: '9999+',
            productId: "0",
            src: 'img/home/seckill_1.jpg',
            category1:'饮品',
            category2:'所有商品',
          }, {
            name: '芝士奶盖四季春',
            price: '10',
            haoping: '9000',
            buy: '9999+',
            productId: "1",
            src: 'img/goodsList/goods1.jpg',
            category1:'饮品',
            category2:'所有商品',            
          }, {
            name: '港式杨梅甘露',
            price: '15.88',
            haoping: '700',
            buy: '733',
            productId: "2",
            src: 'img/goodsList/goods2.jpg',
            category1:'饮品',
            category2:'所有商品',
          }, {
            name: '芋圆葡萄',
            price: '20',
            haoping: '100',
            buy: '333',
            productId: "3",
            src: 'img/goodsList/goods3.jpg',
            category1:'饮品',
            category2:'所有商品',
          }, {
            name: '厚芋泥奶茶',
            price: '30',
            haoping: '100',
            buy: '133',
            productId: "4",
            src: 'img/goodsList/goods4.jpg',
            category1:'饮品',
            category2:'所有商品',
          },
          {
            name: '珍珠奶茶',
            price: '25',
            haoping: '700',
            buy: '773',
            productId: "5",
            src: 'img/goodsList/goods5.jpg',
            category1:'饮品',
            category2:'所有商品',
          },
          {
            name: '椰果奶茶',
            price: '25.9',
            haoping: '77',
            buy: '89',
            productId: "6",
            src: 'img/goodsList/goods6.jpg',
            category1:'饮品',
            category2:'所有商品',
          },
          {
            name: '奥利奥雪王大圣代',
            price: '22.9',
            haoping: '99',
            buy: '215',
            productId: "7",
            src: 'img/goodsList/goods7.jpg',
            category1:'饮品',
            category2:'所有商品',
          },
          {
            name: '三拼霸霸奶茶',
            price: '25.9',
            haoping: '9',
            buy: '19',
            productId: "8",
            src: 'img/goodsList/goods8.jpg',
            category1:'饮品',
            category2:'所有商品',
          },
          {
            name: '珍珠奶茶',
            price: '15.8',
            haoping: '69',
            buy: '88',
            productId: "9",
            src: 'img/goodsList/goods9.jpg',
            category1:'饮品',
            category2:'所有商品',
          }, {
            name: '蜜桃四季春',
            price: '19.9',
            haoping: '700',
            buy: '888',
            productId: "10",
            src: 'img/goodsList/goods10.jpg',
            category1:'饮品',
            category2:'所有商品',
          }, {
            name: '桃喜芒芒',
            price: '9',
            haoping: '888',
            buy: '900',
            productId: "11",
            src: 'img/goodsList/goods11.jpg',
            category1:'饮品',
            category2:'所有商品',
          }, {
            name: '菠萝甜心橙',
            price: '12.9',
            haoping: '999',
            buy: '900',
            productId: "12",
            src: 'img/goodsList/goods12.jpg',
            category1:'饮品',
            category2:'所有商品',
          }, {
            name: '菠萝爱情海',
            price: '29.9',
            haoping: '666',
            buy: '600',
            productId: "13",
            src: 'img/goodsList/goods13.jpg',
            category1:'饮品',
            category2:'所有商品',
          }, {
            name: '百香芒芒',
            price: '29.9',
            haoping: '9999+',
            buy: '9000',
            productId: "14",
            src: 'img/goodsList/goods14.jpg',
            category1:'饮品',
            category2:'所有商品',
          }, {
            name: '咖啡椰椰',
            price: '15.9',
            haoping: '555',
            buy: '500',
            productId: "15",
            src: 'img/goodsList/goods15.jpg',
            category1:'饮品',
            category2:'所有商品',
          },
          {
            name: '冰鲜柠檬水',
            price: '15.8',
            haoping: '9999+',
            buy: '9999+',
            productId: "16",
            src: 'img/goodsList/goods16.jpg'
          },{
            name: '港式杨枝甘露(芋圆版)',
            price: '15.8',
            haoping: '9999+',
            buy: '9999+',
            productId: "17",
            src: 'img/goodsList/goods17.jpg'
          },{
            name: '草莓啵啵',
            price: '15.8',
            haoping: '9999+',
            buy: '9999+',
            productId: "18",
            src: 'img/goodsList/goods18.jpg'
          },{
            name: '黄桃果霸',
            price: '15.8',
            haoping: '9999+',
            buy: '9999+',
            productId: "19",
            src: 'img/goodsList/goods19.jpg'
          },{
            name: '芋圆葡萄',
            price: '15.8',
            haoping: '9999+',
            buy: '9999+',
            productId: "20",
            src: 'img/goodsList/goods20.jpg'
          },{
            name: '满杯百香果',
            price: '15.8',
            haoping: '9999+',
            buy: '9999+',
            productId: "21",
            src: 'img/goodsList/goods21.jpg'
          },{
            name: '鲜橙益菌多',
            price: '15.8',
            haoping: '9999+',
            buy: '9999+',
            productId: "22",
            src: 'img/goodsList/goods22.jpg'
          },{
            name: '柠檬绿茶',
            price: '15.8',
            haoping: '9999+',
            buy: '9999+',
            productId: "23",
            src: 'img/goodsList/goods23.jpg'
          },{
            name: '柠檬红茶',
            price: '15.8',
            haoping: '9999+',
            buy: '9999+',
            productId: "24",
            src: 'img/goodsList/goods24.jpg'
          },{
            name: '棒打鲜橙',
            price: '15.8',
            haoping: '9999+',
            buy: '9999+',
            productId: "25",
            src: 'img/goodsList/goods25.jpg'
          },{
            name: '蜜桃四季春',
            price: '15.8',
            haoping: '9999+',
            buy: '9999+',
            productId: "26",
            src: 'img/goodsList/goods26.jpg'
          }, {
            name: '小油条(店主推荐)',
            price: '15.9',
            haoping: '555',
            buy: '500',
            productId: "27",
            src: 'img/goodsList/花雕醉鸡1.jpg',
            category1:'全部',
            category2:'加菜',
          }, {
            name: '涮汁娃娃菜',
            price: '15.9',
            haoping: '555',
            buy: '500',
            productId: "28",
            src: 'img/goodsList/花雕醉鸡2.jpg',
            category1:'全部',
            category2:'加菜',
          }, {
            name: '五年陈醉鸡双人份',
            price: '15.9',
            haoping: '555',
            buy: '500',
            productId: "29",
            src: 'img/goodsList/花雕醉鸡3.jpg',
            category1:'全部',
            category2:'必点',
          }, {
            name: '独享醉鸡+米饭',
            price: '15.9',
            haoping: '555',
            buy: '500',
            productId: "30",
            src: 'img/goodsList/花雕醉鸡4.jpg',
            category1:'全部',
            category2:'必点',
          }, {
            name: '独享醉鸡+土豆粉',
            price: '15.9',
            haoping: '555',
            buy: '500',
            productId: "31",
            src: 'img/goodsList/花雕醉鸡5.jpg',
            category1:'全部',
            category2:'必点',
          }, {
            name: '贡菜',
            price: '15.9',
            haoping: '555',
            buy: '500',
            productId: "32",
            src: 'img/goodsList/花雕醉鸡6.jpg',
            category1:'全部',
            category2:'加菜',
          },{
            name: '小油条(店主推荐)',
            price: '15.9',
            haoping: '555',
            buy: '500',
            productId: "33",
            src: 'img/goodsList/花雕醉鸡1.jpg',
            category1:'全部',
            category2:'加菜',
          }, {
            name: '涮汁娃娃菜',
            price: '15.9',
            haoping: '555',
            buy: '500',
            productId: "34",
            src: 'img/goodsList/花雕醉鸡2.jpg',
            category1:'全部',
            category2:'加菜',
          }, {
            name: '五年陈醉鸡双人份',
            price: '15.9',
            haoping: '555',
            buy: '500',
            productId: "35",
            src: 'img/goodsList/花雕醉鸡3.jpg',
            category1:'全部',
            category2:'必点',
          }, {
            name: '独享醉鸡+米饭',
            price: '15.9',
            haoping: '555',
            buy: '500',
            productId: "36",
            src: 'img/goodsList/花雕醉鸡4.jpg',
            category1:'全部',
            category2:'必点',
          }, {
            name: '独享醉鸡+土豆粉',
            price: '15.9',
            haoping: '555',
            buy: '500',
            productId: "37",
            src: 'img/goodsList/花雕醉鸡5.jpg',
            category1:'全部',
            category2:'必点',
          }, {
            name: '贡菜',
            price: '15.9',
            haoping: '555',
            buy: '500',
            productId: "38",
            src: 'img/goodsList/花雕醉鸡6.jpg',
            category1:'全部',
            category2:'加菜',
          }
        ];
        var deferred = $q.defer();
        deferred.resolve(obj_goodsListData);
        return deferred.promise;
      }
    }
  });
